import { Component, OnInit } from '@angular/core';
import { HttpService } from '../../service/http.service';
import { HttpRouterService } from '../../service/http-router.service';
import { StorageService } from '../../service/storage.service';
import { Router, ActivatedRoute } from '@angular/router';
import _ from 'underscore';


@Component({
  selector: 'app-screen',
  templateUrl: './screen.component.html',
  styleUrls: ['./screen.component.less']
})
export class ScreenComponent implements OnInit {

  public condition = {
    occupation: '',
    housetype: '',
    cartype: '',
    insurance: '',
    accumulationfund: '',
    socialsecurity: '',
    monthlyincome: '',
    payrolltype: '',
    workinglife: '',
    from_money: '',
    to_money: ''
  };

  public name = '';

  constructor(
    private _http: HttpService,
    private _storage: StorageService,
    private _httpRouter: HttpRouterService,
    private _router: Router,
    private _activatedRoute: ActivatedRoute
  ) { }

  ngOnInit() {
    this._activatedRoute.queryParams.subscribe(params => {
      this.name = params['name'];
    });
  }

  finished() {
    const param = 'occupation=' + this.condition.occupation
      + '&housetype=' + this.condition.housetype
      + '&cartype=' + this.condition.cartype
      + '&insurance=' + this.condition.insurance
      + '&accumulationfund=' + this.condition.accumulationfund
      + '&socialsecurity=' + this.condition.socialsecurity
      + '&monthlyincome=' + this.condition.monthlyincome
      + '&payrolltype=' + this.condition.payrolltype
      + '&workinglife=' + this.condition.workinglife
      + '&from_money' + this.condition.from_money
      + '&to_money=' + this.condition.to_money;

    this._storage.setSession('condition', param);
    if (this.name === 'home') {
      this._router.navigate(['/attache/home'], { queryParams: { param: param } });
    }else if (this.name === 'taodan') {
      this._router.navigate(['/attache/fossick'], { queryParams: { param: param } });
    }
  }

}
